package com.itheima.goods.controller;

import com.itheima.goods.pojo.Category;
import com.itheima.goods.pojo.Spec;
import com.itheima.goods.service.SpecService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping
public class SpecController {

    @Autowired
    private SpecService specService;

    /**
     * 查询所有分类
     * @return
     */
    @GetMapping("/spec/{id}")
    public Result findAll(@PathVariable("id") Integer id){
        return this.specService.findAll(id);
    }

    /**
     * 添加规格
     * @param spec
     */
    @PostMapping("/spec")
    public void findadd( @RequestBody Spec spec){
       this.specService.findadd(spec);
    }

    /**
     * 根据id更新
     * @param id
     * @param
     * @param
     * @return
     */
    @PutMapping("/spec/{id}")
    public Result update(@PathVariable("id") Integer id, @RequestBody Spec spec){
       return this.specService.update(id,spec);
    }

    /**
     * 根据id删除
     * @param id
     */
    @PostMapping("/spec/{id}")
    public void Delete(@PathVariable("id") Integer id){
        this.specService.Delete(id);
    }


    @PostMapping("/spec/search/{page}/{size}")
    public Result findPage(@PathVariable(value = "page",required = true)Integer page,
                           @PathVariable(value = "size",required = true)Integer size){

        return specService.findPage(page,size);
    }
}